From: kaf24@firebug.cl.cam.ac.uk Date: Tue, 13 Jun 2006 10:28:20 +0000 (+0100) Subject: [XEN] Fix compatibility with future guests which may try to X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15972^2~3 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=4f6936097606858467b100e3230d76c17a138dff;p=xen.git [XEN] Fix compatibility with future guests which may try to use hypercalls >= NR_hypercalls. These must fail with ENOSYS, but the current strategy of masking off the high-order bits of the hypercall number means we instead map those hypercalls onto lower-numbered hypercalls with unpredictable results. This patch replaces masking with an explicit compare-and-jump. Signed-off-by: Keir Fraser --- diff --git a/xen/arch/x86/x86_32/entry.S b/xen/arch/x86/x86_32/entry.S index c0bc7e4e01..71cbe20f68 100644 --- a/xen/arch/x86/x86_32/entry.S +++ b/xen/arch/x86/x86_32/entry.S @@ -171,7 +171,8 @@ ENTRY(hypercall) SAVE_ALL(b) sti GET_CURRENT(%ebx) - andl $(NR_hypercalls-1),%eax + cmpl $NR_hypercalls,%eax + jae bad_hypercall PERFC_INCR(PERFC_hypercalls, %eax) #ifndef NDEBUG /* Deliberately corrupt parameter regs not used by this hypercall. */ @@ -261,6 +262,10 @@ process_nmi: 1: bts $_VCPUF_nmi_pending,VCPU_flags(%ebx) jmp test_guest_events +bad_hypercall: + movl $-ENOSYS,UREGS_eax(%esp) + jmp test_all_events + /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS (RING-1) STACK: */ /* {EIP, CS, EFLAGS, [ESP, SS]} */ /* %edx == trap_bounce, %ebx == struct vcpu */ diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index 62bb86510b..853dfa5715 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -130,7 +130,8 @@ ENTRY(syscall_enter) /*hypercall:*/ movq %r10,%rcx - andq $(NR_hypercalls-1),%rax + cmpq $NR_hypercalls,%rax + jae bad_hypercall #ifndef NDEBUG /* Deliberately corrupt parameter regs not used by this hypercall. */ pushq %rdi; pushq %rsi; pushq %rdx; pushq %rcx; pushq %r8 ; pushq %r9 @@ -142,7 +143,6 @@ ENTRY(syscall_enter) rep stosq popq %r9 ; popq %r8 ; popq %rcx; popq %rdx; popq %rsi; popq %rdi movq UREGS_rax(%rsp),%rax - andq $(NR_hypercalls-1),%rax pushq %rax pushq UREGS_rip+8(%rsp) #endif @@ -217,7 +217,11 @@ process_nmi: jmp test_all_events 1: bts $_VCPUF_nmi_pending,VCPU_flags(%rbx) jmp test_guest_events - + +bad_hypercall: + movq $-ENOSYS,UREGS_rax(%rsp) + jmp test_all_events + /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS STACK: */ /* { RCX, R11, [DS-GS,] [CR2,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS } */ /* %rdx: trap_bounce, %rbx: struct vcpu */ diff --git a/xen/include/asm-ia64/config.h b/xen/include/asm-ia64/config.h index c53a7e4f6d..5e197f8849 100644 --- a/xen/include/asm-ia64/config.h +++ b/xen/include/asm-ia64/config.h @@ -97,13 +97,8 @@ extern char _end[]; /* standard ELF symbol */ //#define HZ 1000 // FIXME SMP: leave SMP for a later time -/* A power-of-two value greater than or equal to number of hypercalls. */ #define NR_hypercalls 64 -#if NR_hypercalls & (NR_hypercalls - 1) -#error "NR_hypercalls must be a power-of-two value" -#endif - /////////////////////////////////////////////////////////////// // xen/include/asm/config.h // Natural boundary upon TR size to define xenheap space diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h index 2b80b5643d..bf7e882afc 100644 --- a/xen/include/asm-x86/config.h +++ b/xen/include/asm-x86/config.h @@ -63,13 +63,8 @@ name: #endif -/* A power-of-two value greater than or equal to number of hypercalls. */ #define NR_hypercalls 64 -#if NR_hypercalls & (NR_hypercalls - 1) -#error "NR_hypercalls must be a power-of-two value" -#endif - #ifndef NDEBUG #define MEMORY_GUARD #ifdef __x86_64__ diff --git a/xen/include/asm-x86/multicall.h b/xen/include/asm-x86/multicall.h index 23d7c8e5ba..5fe37176fa 100644 --- a/xen/include/asm-x86/multicall.h +++ b/xen/include/asm-x86/multicall.h @@ -5,48 +5,59 @@ #ifndef __ASM_X86_MULTICALL_H__ #define __ASM_X86_MULTICALL_H__ +#include #include #ifdef __x86_64__ -#define do_multicall_call(_call) \ - do { \ - __asm__ __volatile__ ( \ - "movq "STR(MULTICALL_op)"(%0),%%rax; " \ - "andq $("STR(NR_hypercalls)"-1),%%rax; " \ - "leaq "STR(hypercall_table)"(%%rip),%%rdi; "\ - "leaq (%%rdi,%%rax,8),%%rax; " \ - "movq "STR(MULTICALL_arg0)"(%0),%%rdi; " \ - "movq "STR(MULTICALL_arg1)"(%0),%%rsi; " \ - "movq "STR(MULTICALL_arg2)"(%0),%%rdx; " \ - "movq "STR(MULTICALL_arg3)"(%0),%%rcx; " \ - "movq "STR(MULTICALL_arg4)"(%0),%%r8; " \ - "callq *(%%rax); " \ - "movq %%rax,"STR(MULTICALL_result)"(%0); " \ - : : "b" (_call) \ - /* all the caller-saves registers */ \ - : "rax", "rcx", "rdx", "rsi", "rdi", \ - "r8", "r9", "r10", "r11" ); \ +#define do_multicall_call(_call) \ + do { \ + __asm__ __volatile__ ( \ + " movq "STR(MULTICALL_op)"(%0),%%rax; " \ + " cmpq $("STR(NR_hypercalls)"),%%rax; " \ + " jae 2f; " \ + " leaq "STR(hypercall_table)"(%%rip),%%rdi; "\ + " leaq (%%rdi,%%rax,8),%%rax; " \ + " movq "STR(MULTICALL_arg0)"(%0),%%rdi; " \ + " movq "STR(MULTICALL_arg1)"(%0),%%rsi; " \ + " movq "STR(MULTICALL_arg2)"(%0),%%rdx; " \ + " movq "STR(MULTICALL_arg3)"(%0),%%rcx; " \ + " movq "STR(MULTICALL_arg4)"(%0),%%r8; " \ + " callq *(%%rax); " \ + "1: movq %%rax,"STR(MULTICALL_result)"(%0)\n" \ + ".section .fixup,\"ax\"\n" \ + "2: movq $-"STR(ENOSYS)",%%rax\n" \ + " jmp 1b\n" \ + ".previous\n" \ + : : "b" (_call) \ + /* all the caller-saves registers */ \ + : "rax", "rcx", "rdx", "rsi", "rdi", \ + "r8", "r9", "r10", "r11" ); \ } while ( 0 ) #else -#define do_multicall_call(_call) \ - do { \ - __asm__ __volatile__ ( \ - "pushl "STR(MULTICALL_arg4)"(%0); " \ - "pushl "STR(MULTICALL_arg3)"(%0); " \ - "pushl "STR(MULTICALL_arg2)"(%0); " \ - "pushl "STR(MULTICALL_arg1)"(%0); " \ - "pushl "STR(MULTICALL_arg0)"(%0); " \ - "movl "STR(MULTICALL_op)"(%0),%%eax; " \ - "andl $("STR(NR_hypercalls)"-1),%%eax; " \ - "call *hypercall_table(,%%eax,4); " \ - "movl %%eax,"STR(MULTICALL_result)"(%0); "\ - "addl $20,%%esp; " \ - : : "b" (_call) \ - /* all the caller-saves registers */ \ - : "eax", "ecx", "edx" ); \ +#define do_multicall_call(_call) \ + do { \ + __asm__ __volatile__ ( \ + " pushl "STR(MULTICALL_arg4)"(%0); " \ + " pushl "STR(MULTICALL_arg3)"(%0); " \ + " pushl "STR(MULTICALL_arg2)"(%0); " \ + " pushl "STR(MULTICALL_arg1)"(%0); " \ + " pushl "STR(MULTICALL_arg0)"(%0); " \ + " movl "STR(MULTICALL_op)"(%0),%%eax; " \ + " cmpl $("STR(NR_hypercalls)"),%%eax; " \ + " jae 2f; " \ + " call *hypercall_table(,%%eax,4); " \ + "1: movl %%eax,"STR(MULTICALL_result)"(%0); " \ + " addl $20,%%esp\n" \ + ".section .fixup,\"ax\"\n" \ + "2: movl $-"STR(ENOSYS)",%%eax\n" \ + " jmp 1b\n" \ + ".previous\n" \ + : : "b" (_call) \ + /* all the caller-saves registers */ \ + : "eax", "ecx", "edx" ); \ } while ( 0 ) #endif